package cn.mazexal.exambg.common.models;

/**
 * @author: Mazexal
 * Date: 2025/5/11
 */
public class SingleResponse<T> extends Response {
    private static final long serialVersionUID = 1L;
    private T data;

    public SingleResponse() {
    }

    private Boolean timeOut;

    public Boolean getTimeOut() {
        if (timeOut == null) {
            return false;
        }
        return timeOut;
    }
    public void setTimeOut(Boolean timeOut) {
        this.timeOut = timeOut;
    }


    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> SingleResponse<T> success() {
        SingleResponse<T> response = new SingleResponse();
        response.setSuccess(true);
        return response;
    }

    public static <T> SingleResponse<T> error(String code, String message) {
        SingleResponse<T> response = new SingleResponse();
        response.setSuccess(false);
        response.setErrCode(code);
        response.setErrMessage(message);
        return response;
    }

    public static <T> SingleResponse<T> error(ResponseError error) {
        return error(error.getCode(), error.getMessage());
    }

    public static <T> SingleResponse<T> of(T data) {
        SingleResponse<T> response = new SingleResponse();
        response.setSuccess(true);
        response.setData(data);
        return response;
    }
}
